PanicPointsMaster = AceLibrary ("AceAddon-2.0"):new ("AceConsole-2.0", "AceDB-2.0", "AceHook-2.1", "AceEvent-2.0")

PanicPointsMaster.options =
{
  type = "group",
  args =
  {
    event =
    {
      type = "group",
      name = "event",
      desc = "Event commands",
      args =
      {
        set =
        {
          type = "text",
          name = "set",
          desc = "Set the event for the current raid",
          usage = "<eventName / eventId>",
          current = "Event is currently set to [%2$s]",
          message = "Event is now set to [%2$s]",
          get = "GetEvent",
          set = "SetEvent",
        },
        add =
        {
          type = "text",
          name = "add",
          desc = "Add a new event",
          usage = "<eventName>",
          get = false,
          set = "AddEvent",
        },
        remove =
        {
          type = "text",
          name = "remove",
          desc = "Remove an event",
          usage = "<eventName>",
          get = false,
          set = "RemoveEvent",
          disabled = true,
        },
        list =
        {
          type = "execute",
          name = "list",
          desc = "List all available events",
          func = "ListEvents",
        }
      },
    },
    location =
    {
      type = "group",
      name = "location",
      desc = "Location commands",
      args =
      {
        set =
        {
          type = "text",
          name = "set",
          desc = "Set the location for the current raid",
          usage = "<locationName / locationId>",
          current = "Location is currently set to [%2$s]",
          message = "Location is now set to [%2$s]",
          get = "GetLocation",
          set = "SetLocation",
        },
        add =
        {
          type = "text",
          name = "add",
          desc = "Add a new location",
          usage = "<locationName>",
          get = false,
          set = "AddLocation",
        },
        remove =
        {
          type = "text",
          name = "remove",
          desc = "Remove a location",
          usage = "<locationName>",
          get = false,
          set = "RemoveLocation",
          disabled = true,
        },
        list =
        {
          type = "execute",
          name = "list",
          desc = "List all available locations",
          func = "ListLocations",
        }
      },
    },
    raid =
    {
      type = "group",
      name = "raid",
      desc = "Raid commands",
      args =
      {
        dump =
        {
          type = "execute",
          name = "dump",
          desc = "Create an XML dump of the current raid",
          func = "DumpRaid",
        },
        show =
        {
          type = "execute",
          name = "show",
          desc = "Show all information for the current raid",
          func = "ShowRaid",
        },
        hide =
        {
          type = "execute",
          name = "hide",
          desc = "Hide information for the current raid",
          func = "HideRaid",
        },
        create =
        {
          type = "execute",
          name = "create",
          desc = "Create a new raid",
          func = "CreateRaid",
          disabled = true,
        },
        list =
        {
          type = "execute",
          name = "list",
          desc = "List all stored raids",
          func = "ListRaids",
        },
      },
    },
    item =
    {
      type = "group",
      name = "item",
      desc = "Item commands",
      args =
      {
        list =
        {
          type = "execute",
          name = "list",
          desc = "List all items",
          func = "ListItems",
        },
        show =
        {
          type = "text",
          name = "show",
          desc = "Show information on a specific item",
          usage = "<itemName / itemId / itemLink>",
          get = false,
          set = "ShowItem",
        },
      },
    },
    drop =
    {
      type = "group",
      name = "drop",
      desc = "Drop commands",
      args =
      {
        list =
        {
          type = "execute",
          name = "list",
          desc = "List all drops for the current raid",
          func = "ListDrops",
        }
      },
    },
    member =
    {
      type = "group",
      name = "member",
      desc = "Member commands",
      args =
      {
        list =
        {
          type = "execute",
          name = "list",
          desc = "List all members",
          func = "ListMembers",
        }
      },
    },
    attendee =
    {
      type = "group",
      name = "attendee",
      desc = "Attendee commands",
      args =
      {
        list =
        {
          type = "execute",
          name = "list",
          desc = "List all attendees for the current raid",
          func = "ListAttendees",
        }
      },
    },
  },
}

-- Rarity modifiers for points calculation
PanicPointsMaster.rarities =
{
  [0] = 0,
  [1] = 0,
  [2] = 1,
  [3] = 3,
  [4] = 4,
  [5] = 0,
  [6] = 0,
}

-- Slot modifiers for points calculation
PanicPointsMaster.slots =
{
  ["INVTYPE_HEAD"] = 1,
  ["INVTYPE_NECK"] = 0.55,
  ["INVTYPE_SHOULDER"] = 0.777,
  ["INVTYPE_BODY"] = 1,
  ["INVTYPE_CHEST"] = 1,
  ["INVTYPE_ROBE"] = 1,
  ["INVTYPE_WAIST"] = 0.777,
  ["INVTYPE_LEGS"] = 1,
  ["INVTYPE_FEET"] = 0.777,
  ["INVTYPE_WRIST"] = 0.55,
  ["INVTYPE_HAND"] = 0.777,
  ["INVTYPE_FINGER"] = 0.55,
  ["INVTYPE_TRINKET"] = 0.70,
  ["INVTYPE_CLOAK"] = 0.55,
  ["INVTYPE_WEAPON"] = 0.42,
  ["INVTYPE_SHIELD"] = 0.55,
  ["INVTYPE_2HWEAPON"] = 1,
  ["INVTYPE_WEAPONMAINHAND"] = 0.42,
  ["INVTYPE_WEAPONOFFHAND"] = 0.42,
  ["INVTYPE_HOLDABLE"] = 0.55,
  ["INVTYPE_RANGED"] = 0.30,
  ["INVTYPE_THROWN"] = 0.30,
  ["INVTYPE_RANGEDRIGHT"] = 0.30,
  ["INVTYPE_RELIC"] = 0.30,
}

-- Table of special items to check when something is looted without a target, to determine event
PanicPointsMaster.specialItems =
{
  -- Hardpacked Snowball
  ["21038"] = "Hardpacked Snowdrift",
  -- The Eye of Divinity
  ["18646"] = "Majordomo Executus",
  -- Ancient Petrified Leaf
  ["18703"] = "Majordomo Executus",
}

-- Default events, imported into self.db
PanicPointsMaster.defaultEvents =
{
  ["Molten Core"] =
  {
    "Lucifron",
    "Magmadar",
    "Gehennas",
    "Garr",
    "Baron Geddon",
    "Shazzrah",
    "Golemagg the Incinerator",
    "Sulfuron Harbinger",
    "Majordomo Executus",
    "Ragnaros",
  },
  ["Blackwing Lair"] =
  {
    "Razorgore the Untamed",
    "Vaelastrasz the Corrupt",
    "Broodlord Lashlayer",
    "Firemaw",
    "Ebonroc",
    "Flamegor",
    "Chromaggus",
    "Nefarian",
  }
}

-- Default Locations, imported into self.db
PanicPointsMaster.defaultLocations =
{
  "Molten Core",
  "Blackwing Lair",
}

-- Called upon ADDON_LOADED
function PanicPointsMaster:OnInitialize ()
  self:RegisterDB ("PanicPointsMasterDB", "PanicPointsMasterDBPC")
  self:RegisterDefaults ("profile",
  {
    raids = {},
    events = PanicPointsMaster.defaultEvents,
    locations = PanicPointsMaster.defaultLocations,
    members = {},
    items = {},
  })

  self.options.args.location.args.set.validate = self.db.profile.locations

  self:RegisterChatCommand ({"/panicpointsmaster", "/ppm"}, PanicPointsMaster.options)

  StaticPopupDialogs["PANICPOINTSMASTER_AUTOLOCATION"] =
  {
    text = "Do you wish to change the current raid location to [%s]?",
    button1 = "Yes",
    button2 = "No",
    OnAccept = function (location) self:SetLocation (location) end,
    timeout = 0,
  }

  StaticPopupDialogs["PANICPOINTSMASTER_AUTOEVENT"] =
  {
    text = "Do you wish to change the current raid event to [%s]?",
    button1 = "Yes",
    button2 = "No",
  OnAccept = function (event) self:SetEvent (event) end,
  }

  StaticPopupDialogs["PANICPOINTSMASTER_AUTORAID"] =
  {
    text = "Do you wish to create a new raid for [%s]?",
    button1 = "Yes",
    button2 = "No",
    OnAccept = function (event) self:CreateRaid (event) end
  }

  local normalFont, _, _ = GameFontNormal:GetFont ()

  self.frames = {}
  self.frames.raid = CreateFrame ("Frame", nil, UIParent)
	self.frames.raid:Hide ()
	self.frames.raid:SetWidth (390)
	self.frames.raid:SetHeight (600)
	self.frames.raid:EnableMouse (true)
	self.frames.raid:SetMovable (true)
	self.frames.raid:RegisterForDrag ("LeftButton")
	self.frames.raid:SetScript ("OnDragStart", function () this:StartMoving () end)
	self.frames.raid:SetScript ("OnDragStop", function () this:StopMovingOrSizing () end)
	self.frames.raid:SetBackdrop (
	{
		bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background", tile = true, tileSize = 16,
		edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", edgeSize = 16,
		insets =
		{
		  left = 4,
		  right = 4,
		  top = 4,
		  bottom = 4
		},
	})
	self.frames.raid:SetBackdropBorderColor (.5, .5, .5)
	self.frames.raid:SetBackdropColor (0,0,0)
	self.frames.raid:ClearAllPoints ()
	self.frames.raid:SetPoint ("CENTER", WorldFrame, "CENTER", 0, 0)

	--[[
	self.frames.attendeeScroll = CreateFrame ("ScrollFrame", "PanicPointsMasterAttendeeScrollFrame", self.frames.raid, "FauxScrollFrameTemplate")
	self.frames.attendeeScroll.owner = self
	self.frames.attendeeScroll:SetParent (self.frames.raid)
	self.frames.attendeeScroll:SetWidth (285)
	self.frames.attendeeScroll:SetHeight (240)
	self.frames.attendeeScroll:SetPoint ("TOPLEFT", self.frames.raid, "TOPLEFT")
	self.frames.attendeeScroll:SetScript("OnVerticalScroll", function () FauxScrollFrame_OnVerticalScroll (16, function () this.owner:UpdateScrollBar () end)	end)
	]]--

	self.frames.currentRaid = self.frames.raid:CreateFontString (nil,"OVERLAY")
	self.frames.currentRaid:SetFont (normalFont, 12)
	self.frames.currentRaid:SetWidth (130)
	self.frames.currentRaid:SetJustifyH ("LEFT")
	self.frames.currentRaid:SetJustifyV ("TOP")
	self.frames.currentRaid:SetText ("currentRaid")
	self.frames.currentRaid:ClearAllPoints ()
	self.frames.currentRaid:SetPoint ("TOPLEFT", self.frames.raid, "TOPLEFT", 20, -20)

	self.frames.currentLocation = self.frames.raid:CreateFontString ("PanicPointsMasterCurrentLocation", "OVERLAY")
	self.frames.currentLocation:SetFont (normalFont, 12)
	self.frames.currentLocation:SetWidth (130)
	self.frames.currentLocation:SetJustifyH ("LEFT")
	self.frames.currentLocation:SetJustifyV ("TOP")
	self.frames.currentLocation:SetText ("currentLocation")
	self.frames.currentLocation:ClearAllPoints ()
	self.frames.currentLocation:SetPoint ("TOPLEFT", self.frames.currentRaid, "TOPLEFT", 0, -20)

	self.frames.currentEvent = self.frames.raid:CreateFontString (nil,"OVERLAY")
	self.frames.currentEvent:SetFont (normalFont, 12)
	self.frames.currentEvent:SetWidth (130)
	self.frames.currentEvent:SetJustifyH ("LEFT")
	self.frames.currentEvent:SetJustifyV ("TOP")
	self.frames.currentEvent:SetText ("currentEvent")
	self.frames.currentEvent:ClearAllPoints ()
	self.frames.currentEvent:SetPoint ("TOPLEFT", self.frames.currentLocation, "TOPLEFT", 0, -20)

	self.frames.leftList = self.frames.raid:CreateFontString (nil,"OVERLAY")
	self.frames.leftList:SetFont (normalFont, 12)
	self.frames.leftList:SetWidth (130)
	self.frames.leftList:SetJustifyV ("TOP")
	self.frames.leftList:SetText ("leftList")
	self.frames.leftList:ClearAllPoints ()
	self.frames.leftList:SetPoint ("TOPLEFT", self.frames.currentEvent, "TOPLEFT", -20, -20)

	self.frames.middleList = self.frames.raid:CreateFontString (nil,"OVERLAY")
	self.frames.middleList:SetFont (normalFont, 12)
	self.frames.middleList:SetWidth (130)
	self.frames.middleList:SetJustifyV ("TOP")
	self.frames.middleList:SetText ("middleList")
	self.frames.middleList:ClearAllPoints ()
	self.frames.middleList:SetPoint ("TOPLEFT", self.frames.leftList, "TOPRIGHT")

	self.frames.rightList = self.frames.raid:CreateFontString (nil,"OVERLAY")
	self.frames.rightList:SetFont (normalFont, 12)
	self.frames.rightList:SetWidth (130)
	self.frames.rightList:SetJustifyV ("TOP")
	self.frames.rightList:SetText ("rightList")
	self.frames.rightList:ClearAllPoints ()
	self.frames.rightList:SetPoint ("TOPLEFT", self.frames.middleList, "TOPRIGHT")

end

-- Called upon PLAYER_LOGIN / Enabling
function PanicPointsMaster:OnEnable ()
  self:RegisterEvent ("LOOT_OPENED", "OnLootOpened")
  self:RegisterEvent ("PLAYER_TARGET_CHANGED", "OnPlayerTargetChanged")
  self:RegisterEvent ("ZONE_CHANGED_NEW_AREA", "OnZoneChangedNewArea")
  self:Hook ("GiveMasterLoot", "GiveMasterLoot", true)
end

-- Called upon disabling
function PanicPointsMaster:OnDisable ()
  self:Unhook ("GiveMasterLoot")
  self:UnregisterEvent ("ZONE_CHANGED_NEW_AREA")
  self:UnregisterEvent ("PLAYER_TARGET_CHANGED")
  self:UnregisterEvent ("LOOT_OPENED")
end

function PanicPointsMaster:GetCurrentRaidId ()
  
  local raidId = table.getn (self.db.profile.raids)
  
  if (raidId == 0) then
    return nil
  else
    return raidId
  end  
end

function PanicPointsMaster:GetLocation (raidId)

  raidId = raidId or self:GetCurrentRaidId ()

  if (not raidId) then
    DEFAULT_CHAT_FRAME:AddMessage ("No valid raid specified")
    return
  end

  return self.db.profile.raids[raidId].location
end

function PanicPointsMaster:SetLocation (location, raidId)

  raidId = raidID or self:GetCurrentRaidId ()

  if (not raidId) then
    DEFAULT_CHAT_FRAME:AddMessage ("No valid raid specified")
    return
  end

  -- Set the specified location, and make sure our event validation matches the new location
  self.db.profile.raids[raidId].location = location
  self.options.args.event.args.set.validate = self.db.profile.events[location]
  
  DEFAULT_CHAT_FRAME:AddMessage ("Current raid location set to [" .. location .. "].")
end

-- Insert a new location and set up the event structure
function PanicPointsMaster:AddLocation (location)
  table.insert (self.db.profile.locations, location)
  self.db.profile.events[location] = {}
end

function PanicPointsMaster:AddEvent (event, location)
  if (not location) then
    local raidId = self:GetCurrentRaidId ()
    location = self.db.profile.raids[raidId].location
  end
  
  table.insert (self.db.profile.events[location], event)
end

function PanicPointsMaster:GetEvent (raidId)

  raidId = raidId or self:GetCurrentRaidId ()
  
  if (not raidId) then
    DEFAULT_CHAT_FRAME_AddMessage ("No valid raid specified")
    return
  end

  return self.db.profile.raids[raidId].event
end

function PanicPointsMaster:SetEvent (event, raidId)

  raidId = raidId or self:GetCurrentRaidId ()

  if (not raidId) then
    DEFAULT_CHAT_FRAME:AddMessage ("No valid raid specified")
  end
  
  self.db.profile.raids[raidId].event = event

  DEFAULT_CHAT_FRAME:AddMessage ("Current raid event set to [" .. event .. "].")
end

function PanicPointsMaster:GiveMasterLoot (lootIndex, candidateIndex)
  local itemLink = GetLootSlotLink (lootIndex)
  local _, _, itemId = string.find (itemLink, "^|%x+|Hitem:(%d+):.+|h%[.+%]")
  local _, _, _, _, _, _, _, _, _, _ = GetItemInfo (itemId)

  local itemPoints = this:CalculatePoints (itemId)
  local memberName = GetMasterLootCandidate (candidateIndex)

  local drop =
  {
    itemId = itemId,
    memberName = memberName,
    itemPoints = itemPoints,
  }

  local raidId = self:GetCurrentRaidId ()
  table.insert (self.db.profile.raids[raidId].drops, drop)

  self.hooks.GiveMasterLoot (lootIndex, candidateIndex)
end

function PanicPointsMaster:CalculatePoints (itemId)

  local points = 0;

  -- If we haven't already seen this item before
  if (not self.db.profile.items[itemId]) then
    local _, _, itemRarity, itemLevel, _, _, _, _, itemSlot, _ = GetItemInfo (itemId)

    -- If this item has a slot, calculate its points
    if (itemSlot ~= "") then
      points = itemLevel * self.slots[itemSlot] * self.rarities[itemRarity]
    end

    -- Store the (calculated) points
    self.db.profile.items[itemId] = points
  else
    points = self.db.profile.items[itemId]
  end

  return points
end

function PanicPointsMaster:OnLootOpened ()
  -- See if we can read a name from our current target
  local name, _ = UnitName ("target")

  -- See if we can decide a name through the loot
  if (not name) then
    for i = 1, GetNumLootItems () do
      if (LootSlotIsItem (i)) then
        local itemLink = GetLootSlotLink (i)
        local _, _, itemId = string.find (itemLink, "^|%x+|Hitem:(%d+):.+|h%[.+%]")

        if (self.specialItems[itemId]) then
          name = self.specialItems[itemId]
        end
      end
    end
  end

  local raidId = PanicPointsMaster:GetCurrentRaidId ()
  
  if (not raidId) then
    DEFAULT_CHAT_FRAME:AddMessage ("No current raid for event selection")
    return
  end

  -- If we have found a name
  if (name) then
    -- If this target is a valid event for the current location
    if (self.db.profile.events[self.db.profile.raids[raidId].location] and self.db.profile.events[self.db.profile.raids[raidId].location][name]) then
      local dialog = StaticPopup_Show ("PANICPOINTSMASTER_AUTORAID", name)
      if (dialog) then
        dialog.data = name
      end
    end
  end
end

function PanicPointsMaster:OnPlayerTargetChanged ()
  if (UnitClassification ("target") ~= "worldboss") then
    return
  end

  local name, _ = UnitName ("target")
  local raidId = self:GetCurrentRaidId ()
  
  if (not raidId) then
    DEFAULT_CHAT_FRAME:AddMessage ("No current raid for event selection")
    return
  end

  -- If this target is a valid event for the current location
  if (self.db.profile.events[self.db.profile.raids[raidId].location] and self.db.profile.events[self.db.profile.raids[raidId].location][name]) then
    local dialog = StaticPopup_Show ("PANICPOINTSMASTER_AUTOEVENT", name)
    if (dialog) then
      dialog.data = name
    end
  end
end

function PanicPointsMaster:CreateRaid (event)

  local raid =
  {
    event = nil,
    location = nil,
    attendees = {},
    drops = {},
  }

  local zone = GetRealZoneText ()


  -- See if a location exists for the current zone
  for key, value in pairs (self.db.profile.locations) do
    if (zone == value) then
      raid.location = zone
      
      if (event) then
        raid.event = event
      else
        local name, _ = UnitName ("target")
    
        -- If this target is a valid event for the current location
        if (self.db.profile.events[zone] and self.db.profile.events[zone][name]) then
          raid.event = name
        end
      end

      break
    end
  end

  for i = 1, GetNumRaidMembers () do
    local name, _ = UnitName ("raid" .. i)

    if (not self.db.profile.members[name]) then
      self.db.profile.members[name] = {}
    end

    raid.attendees[name] = {}
  end

  table.insert (self.db.profile.raids, raid)
end

function PanicPointsMaster:DumpRaid (raidId)

  if (not raidId) then
    raidId = self:GetCurrentRaidId ()
  end

  local dump = ""

  dump = dump .. "<raid>\n"
  dump = dump .. "  <location>" .. self.db.profile.raids[raidId].location .. "</location>\n"
  dump = dump .. "  <event>" .. self.db.profile.raids[raidId].event .. "</event>\n"
  dump = dump .. "  <attendees>\n"

  for key, value in pairs (self.db.profile.raids[raidId].attendees) do
    dump = dump .. "    <attendee>" .. key .. "</attendee>\n"
  end

  dump = dump .. "  </attendees>\n"

  dump = dump .. "  <drops>\n"

  for key, value in pairs (self.db.profile.raids[raidId].drops) do
    dump = dump .. "    <drop>\n"
    dump = dump .. "      <itemid>" .. value.itemId .. "</itemid>\n"
    dump = dump .. "      <membername>" .. value.memberName .. "</membername>\n"
    dump = dump .. "      <itempoints>" .. value.itemPoints .. "</itempoints>\n"
    dump = dump .. "    </drop>\n"
  end

  dump = dump .. "  </drops>\n"

  dump = dump .. "</raid>\n"

  --@todo: Create frame for display of dump string, select and focus string

  self.db.profile.dump = dump
end

function PanicPointsMaster:HideRaid ()
  self.frames.raid:Hide ()
end

function PanicPointsMaster:ShowRaid (raidId)

  if (not raidId) then
    raidId = self:GetCurrentRaidId ()
  end

  self.frames.raid:Show ()

  local i = 0
  local leftText = ""
  local middleText = ""
  local rightText = ""

  for key, value in pairs (self.db.profile.raids[raidId].attendees) do
    if ((i % 3) == 0) then
      leftText = leftText .. key .. "\n"
    elseif ((i % 3) == 1) then
      middleText = middleText .. key .. "\n"
    else
      rightText = rightText .. key .. "\n"
    end

    i = i + 1
  end

  self.frames.leftList:SetText (leftText)
  self.frames.middleList:SetText (middleText)
  self.frames.rightList:SetText (rightText)

  i = 0

  self.frames.drops = {}

  local normalFont, _, _ = GameFontNormal:GetFont ()

  for key, value in pairs (self.db.profile.raids[raidId].drops) do
    self.frames.drops[i] = {}

    local _, itemLink, _, _, _, _, _, _, _, itemTexture = GetItemInfo (value.itemId)

	  self.frames.drops[i].thumbnail = CreateFrame ("Frame", nil, self.frames.raid)
	  self.frames.drops[i].thumbnail:SetWidth (24)
	  self.frames.drops[i].thumbnail:SetHeight (24)
	  self.frames.drops[i].thumbnail:SetBackdrop (
  	{
	    bgFile = itemTexture, tile = false,
	  })
	  self.frames.drops[i].thumbnail:ClearAllPoints ()

	  if (i == 0) then
    	self.frames.drops[i].thumbnail:SetPoint ("TOPLEFT", self.frames.leftList, "BOTTOMLEFT", 20, -20)
    else
      self.frames.drops[i].thumbnail:SetPoint ("TOPLEFT", self.frames.drops[i - 1].thumbnail, "BOTTOMLEFT", 0, -2)
    end

  	self.frames.drops[i].details = self.frames.raid:CreateFontString (nil, "OVERLAY")
  	self.frames.drops[i].details:SetFont (normalFont, 12)
  	self.frames.drops[i].details:SetJustifyH ("LEFT")
  	self.frames.drops[i].details:SetJustifyV ("TOP")
  	self.frames.drops[i].details:SetText (itemLink .. " by " .. value.memberName .. " for " .. value.itemPoints)
  	self.frames.drops[i].details:ClearAllPoints ()
  	self.frames.drops[i].details:SetPoint ("TOPLEFT", self.frames.drops[i].thumbnail, "TOPRIGHT", 2, -5)

    i = i + 1
  end
end

function PanicPointsMaster:OnZoneChangedNewArea ()

  local zone = GetRealZoneText ()
  local raidId = self:GetCurrentRaidId ()

  if (zone == self.db.profile.raids[raidId].location) then
    return
  end

  for key, value in pairs (self.db.profile.locations) do
    if (zone == value) then
      local dialog = StaticPopup_Show ("PANICPOINTSMASTER_AUTOLOCATION", zone)
      if (dialog) then
        dialog.data = zone
      end
    end
  end
end

function PanicPointsMaster:UpdateScrollBar ()
  FauxScrollFrame_Update (self.frames.attendeeScroll, 20, 5, 16)
  DEFAULT_CHAT_FRAME:AddMessage ("Scrollbar at " .. FauxScrollFrame_GetOffset (self.frames.attendeeScroll));
end

function PanicPointsMaster:ListLocations ()
  for key, value in pairs (self.db.profile.locations) do
    DEFAULT_CHAT_FRAME:AddMessage (value)
  end
end

function PanicPointsMaster:ListMembers ()
  for key, value in pairs (self.db.profile.members) do
    DEFAULT_CHAT_FRAME:AddMessage (key)
  end
end

function PanicPointsMaster:ListItems ()
  for key, value in pairs (self.db.profile.items) do
  end
end

function PanicPointsMaster:ShowItem (item)
end

function PanicPointsMaster:ListRaids ()
end

function PanicPointsMaster:ListEvents (location)
  if (not location) then
    local raidId = self:GetCurrentRaidId ()
    location = self.db.profile.raids[raidId].location
  end
  
  if (self.db.profile.events[location]) then
    DEFAULT_CHAT_FRAME:AddMessage ("Events for " .. location)
    for key, value in pairs (self.db.profile.events[location]) do
      DEFAULT_CHAT_FRAME:AddMessage (value)
    end
  else
    DEFAULT_CHAT_FRAME:AddMessage ("No events for " .. location)
  end
end

function PanicPointsMaster:RemoveEvent ()
end

function PanicPointsMaster:RemoveLocation ()
end

function PanicPointsMaster:ListDrops (raidId)
  if (not raidId) then
    raidId = self:GetCurrentRaidId ()
  end
  
  for key, value in pairs (self.db.profile.raids[raidId].drops) do
    DEFAULT_CHAT_FRAME:AddMesssage (value)
  end
end

function PanicPointsMaster:ListAttendees ()
  if (not raidId) then
    raidId = self:GetCurrentRaidId ()
  end
  
  for key, value in pairs (self.db.profile.raids[raidId].attendees) do
    DEFAULT_CHAT_FRAME:AddMesssage (value)
  end  
end